package com.tieto.user.service;

import javax.jws.WebParam;
import javax.jws.WebService;

import com.tieto.user.model.User;

/**
 * UserServiceImpl is an WebService implementation of UserService. Can not use
 * delegate design pattern, since UserRepository uses overloaded methods, and
 * apparently WS-I profile does not support them. Even so, it might be better to
 * reveal only some of the UserRepository methods as WebService. Also,
 * WebService does not support lists without extensions. WebParam annotations
 * are not necessary, but adds proper names to parameters in WSDL.
 */
@WebService
public interface UserService {
    /**
     * Returns all users from repository.
     */
    User[] findAll();

    /**
     * Creates a user to repository.
     * 
     * @throws NullPointerException
     *             if the username is null
     * @throws IllegalArgumentException
     *             if the username is blank
     */
    User create(@WebParam(name = "user") User user);

    /**
     * Updates a user in repository.
     */
    User update(@WebParam(name = "user") User user);

    /**
     * Returns a user by username.
     */
    User findOne(@WebParam(name = "username") String username);

    /**
     * Returns a user by username.
     */
    User findByEmail(@WebParam(name = "email") String email);

    /**
     * Returns true if a user by username exists.
     */
    boolean exists(@WebParam(name = "username") String username);

    /**
     * Deletes a user by username.
     */
    void delete(@WebParam(name = "username") String username);

    /**
     * Returns the count of users in repository.
     */
    long count();
}
